package com.hooda.container;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Connector extends Thread {

    private int port;

    private Service service;

    private ServerSocket serverSocket = null;

    public Connector(int port, Service service) {
        this.port = port;
        this.service = service;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Socket socket = serverSocket.accept();
                service.receive(socket);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public void init() {
        try {
            serverSocket = new ServerSocket(port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void start() {

    }

    public void destroy() {

    }

}
